package io.github.talelin.latticy.service.impl;

import io.github.talelin.latticy.model.ActivityDO;
import io.github.talelin.latticy.mapper.ActivityMapper;
import io.github.talelin.latticy.model.ActivityDetailDO;
import io.github.talelin.latticy.model.CouponDO;
import io.github.talelin.latticy.service.ActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.talelin.latticy.service.CouponService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generator@TaleLin
 * @since 2021-06-15
 */
@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, ActivityDO> implements ActivityService {

    @Autowired
    private CouponService couponService;

    @Override
    public ActivityDetailDO getDetailById(Long id) {
        ActivityDO activityDO = this.getBaseMapper().selectById(id);
        List<Integer> coupons = couponService.getCouponsByActivityId(id);
        ActivityDetailDO activityDetailDO = new ActivityDetailDO();
        BeanUtils.copyProperties(activityDO, activityDetailDO);
        // 方法一
        List<Integer> couponIdList = this.couponService.getCouponsByActivityId(id);
        // 方法二
//        List<CouponDO> couponDOList = this.couponService.lambdaQuery().eq(CouponDO::getActivityId, id).list();
//        List<Integer> couponIdList = couponDOList.stream().map(couponDO -> {
//             return couponDO.getId().intValue();
//        }).collect(Collectors.toList());
//        activityDetailDO.setCouponIds(couponIdList);
        return activityDetailDO;
    }
}
